Add --release flag to `cargo doc`
authorAlex Crichton <alex@alexcrichton.com>
Sat, 5 Sep 2015 00:09:24 +0000 (17:09 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 8 Sep 2015 18:30:35 +0000 (11:30 -0700)
While this may not necessarily make sense all the time, this enables Cargo to
not rebuild anything if a `cargo build --release` was previously executed.

src/bin/doc.rs
tests/test_cargo_doc.rs

index 6bc43a86b04ef326863b102a6110a2a0ef3db87e..8fa2bae7cc0350269f878a9c588a6349228b64d6 100644 (file)
@@ -12,6 +12,7 @@ struct Options {
     flag_no_deps: bool,
     flag_open: bool,
     flag_verbose: bool,
+    flag_release: bool,
     flag_quiet: bool,
     flag_color: Option<String>,
     flag_package: Option<String>,
@@ -29,6 +30,7 @@ Options:
     -p SPEC, --package SPEC  Package to document
     --no-deps                Don't build documentation for dependencies
     -j N, --jobs N           The number of jobs to run in parallel
+    --release                Build artifacts in release mode, with optimizations
     --features FEATURES      Space-separated list of features to also build
     --no-default-features    Do not build the `default` feature
     --target TRIPLE          Build for the target triple
@@ -63,7 +65,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             spec: options.flag_package.as_ref().map(|s| &s[..]),
             exec_engine: None,
             filter: ops::CompileFilter::Everything,
-            release: false,
+            release: options.flag_release,
             mode: ops::CompileMode::Doc {
                 deps: !options.flag_no_deps,
             },
index 87dd0ed25415dafe9a277af365b70f014f8d4cc2..42c7a95064124b693be8cd2339099d6c09c8c60b 100644 (file)
@@ -1,5 +1,5 @@
 use support::{project, execs, path2url};
-use support::COMPILING;
+use support::{COMPILING, RUNNING};
 use hamcrest::{assert_that, existing_file, existing_dir, is_not};
 
 fn setup() {
@@ -347,3 +347,23 @@ test!(target_specific_documented {
     assert_that(p.cargo_process("doc"),
                 execs().with_status(0));
 });
+
+test!(doc_release {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("build").arg("--release"),
+                execs().with_status(0));
+    assert_that(p.cargo("doc").arg("--release").arg("-v"),
+                execs().with_status(0)
+                       .with_stdout(&format!("\
+{compiling} foo v0.0.1 ([..])
+{running} `rustdoc src[..]lib.rs [..]`
+", compiling = COMPILING, running = RUNNING)));
+});